﻿Imports System.Text.RegularExpressions
Imports DAL
Imports System.Linq

Public Class UCEmployeBureau
    REM detecter modification TEL

    Dim employe As EmployeBureau

    Public Event Modification As EventHandler

    Private Sub UCGestionEmployeV2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        employe = New EmployeBureau
        TxtVehicule.SelectedIndex = 0
    End Sub

    Public Sub Sauver_Employe(ByVal mode As Mode, ByVal noEmp As Employe)
        Dim emp As New EmployeBureau
        If mode = mode.ajout Then
            emp.Employe = noEmp
            bd.EmployeBureaus.InsertOnSubmit(emp)
            bd.SubmitChanges()
        End If
        emp = (From x In bd.EmployeBureaus Where x.IDEmploye = noEmp.ID Select x).First
        With emp

            .CaisseBanque = TxtnoCaisse.Text
            .Folio = TxtNoFolio.Text
            .NoPermis = TxtNoPermis.Text
            .Transit = TxtNoTransit.Text
            .Vehicule = IIf(TxtVehicule.SelectedIndex = 1, True, False)

        End With
        bd.SubmitChanges()

    End Sub

    Public Sub afficherEmploye(ByVal emp As Integer)
        employe = (From X In bd.EmployeBureaus Where X.IDEmploye = emp Select X).First
        With employe
            TxtnoCaisse.Text = .CaisseBanque
            TxtNoFolio.Text = .Folio
            TxtNoPermis.Text = .NoPermis
            TxtNoTransit.Text = .Transit
            TxtVehicule.SelectedIndex = IIf(.Vehicule, 1, 0)
        End With
    End Sub
    'Permet de détecter les changements dans les zones de texte (Textbox, DateTimePicker, Combobox...), radio, check
    'Ne détecte pas les , liste
    Private Sub detecterChangement(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtnoCaisse.TextChanged, TxtNoFolio.TextChanged, TxtNoPermis.TextChanged, TxtNoTransit.TextChanged, TxtVehicule.SelectedIndexChanged

        If TypeOf (sender) Is Boolean AndAlso sender = True Then
            RaiseEvent Modification(True, Nothing)
            Exit Sub
        Else
            RaiseEvent Modification(True, Nothing)
        End If
    End Sub

    Public Sub ViderChamps()
        For Each iem In Me.Controls
            Select Case True
                Case iem.name.substring(0, 3) = "TLP"
                    For Each item In iem.Controls
                        Select Case True
                            Case item.name.substring(0, 3) = "Txt" Or item.name.substring(0, 3) = "Txt"
                                item.text = ""
                        End Select
                    Next
            End Select
        Next
        TxtVehicule.SelectedIndex = 0
    End Sub

    Public Sub lectureSeule(ByVal mode As Boolean)
        For Each item In Me.Controls
            Select Case item.GetType()
                Case GetType(TextBox)
                    CType(item, TextBox).ReadOnly = mode
                    CType(item, TextBox).ForeColor = Color.Black
                    CType(item, TextBox).BackColor = Color.White
                Case GetType(DateTimePicker)
                    CType(item, DateTimePicker).Enabled = Not mode
                Case GetType(CheckBox)
                    CType(item, CheckBox).Enabled = Not mode
                Case GetType(RadioButton)
                    CType(item, RadioButton).Enabled = Not mode
                Case GetType(ListView)
                    CType(item, ListView).Enabled = Not mode
                Case GetType(ListBox)
                    CType(item, ListBox).Enabled = Not mode
                Case GetType(PictureBox)
                    CType(item, PictureBox).Enabled = Not mode
                Case GetType(ComboBox)
                    CType(item, ComboBox).Enabled = Not mode
            End Select
        Next
    End Sub
End Class
